<template>
  <div class="bar-chart" ref="barChartRef">LineChart</div>
</template>

<script lang="ts">
export default {
  name: "BarChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { onMounted, ref } from "vue";

const barChartRef = ref();
// 必须在onMounted中完成，此时才会有DOM元素
onMounted(() => {
  const myEchart = echarts.init(barChartRef.value);
  const option = {
    xAxis: {
      data: [
        "一月",
        "二月",
        "三月",
        "四月",
        "五月",
        "六月",
        "七月",
        "八月",
        "九月",
        "十月",
        "十一月",
        "十二月",
      ],
      show: false,
    },
    yAxis: {
      show: false,
    },
    series: {
      type: "bar",
      data: [25, 20, 29, 18, 23, 25, 20, 29, 18, 23, 30, 15],
    },
    grid: {
      top: 10,
      bottom: 0,
      left: 0,
      right: 0,
    },
  };
  myEchart.setOption(option);
});
</script>

<style scoped>
.bar-chart {
  width: 100%;
  height: 100%;
}
</style>
